package com.mowh.multithreading.future;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

/**
 * @author mowh1gd
 * @create 2023/11/24 16:51
 */
public class FutureDataTask extends FutureTask<RealData> implements Data {
    public FutureDataTask(Callable<RealData> callable) {//生成数据后给FutureData的realData属性赋值的操作（即setter）已被抽象化，不再需要setter函数。
        super(callable);
    }
    @Override
    public String getContent() {
        String content;
        try {
            content = get().getContent();//get()直接返回泛函RealData
        } catch (ExecutionException | InterruptedException e) {
            throw new RuntimeException(e);
        }
        return content;
    }
}
